package com.ruoyi.web.controller.material;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.material.domain.SmesMaterialArriveBill;
import com.ruoyi.mes.material.service.ISmesMaterialArriveBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购订单Controller
 * 
 * @author simpsense
 * @date 2020-12-10
 */
@RestController
@RequestMapping("/material/arriveBill")
public class SmesMaterialArriveBillController extends BaseController
{
    @Autowired
    private ISmesMaterialArriveBillService smesMaterialArriveBillService;

    /**
     * 查询采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('material:arriveBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesMaterialArriveBill smesMaterialArriveBill)
    {
        startPage();
        List<SmesMaterialArriveBill> list = smesMaterialArriveBillService.selectSmesMaterialArriveBillList(smesMaterialArriveBill);
        return getDataTable(list);
    }

    /**
     * 导出采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('material:arriveBill:export')")
    @Log(title = "采购订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesMaterialArriveBill smesMaterialArriveBill)
    {
        List<SmesMaterialArriveBill> list = smesMaterialArriveBillService.selectSmesMaterialArriveBillList(smesMaterialArriveBill);
        ExcelUtil<SmesMaterialArriveBill> util = new ExcelUtil<SmesMaterialArriveBill>(SmesMaterialArriveBill.class);
        return util.exportExcel(list, "arriveBill");
    }

    /**
     * 获取采购订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:arriveBill:query')")
    @GetMapping(value = "/{arriveBillNo}")
    public AjaxResult getInfo(@PathVariable("arriveBillNo") String arriveBillNo)
    {
        return AjaxResult.success(smesMaterialArriveBillService.selectSmesMaterialArriveBillById(arriveBillNo));
    }

    /**
     * 新增采购订单
     */
    @PreAuthorize("@ss.hasPermi('material:arriveBill:add')")
    @Log(title = "采购订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesMaterialArriveBill smesMaterialArriveBill)
    {
        return toAjax(smesMaterialArriveBillService.insertSmesMaterialArriveBill(smesMaterialArriveBill));
    }

    /**
     * 修改采购订单
     */
    @PreAuthorize("@ss.hasPermi('material:arriveBill:edit')")
    @Log(title = "采购订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesMaterialArriveBill smesMaterialArriveBill)
    {
        return toAjax(smesMaterialArriveBillService.updateSmesMaterialArriveBill(smesMaterialArriveBill));
    }

    /**
     * 删除采购订单
     */
    @PreAuthorize("@ss.hasPermi('material:arriveBill:remove')")
    @Log(title = "采购订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{arriveBillNos}")
    public AjaxResult remove(@PathVariable String[] arriveBillNos)
    {
        return toAjax(smesMaterialArriveBillService.deleteSmesMaterialArriveBillByIds(arriveBillNos));
    }
}
